CircuitBreaker

JS/TS-friendly facade over com.sorinirmies.arrow.resiliencekit.CircuitBreaker.

import { CircuitBreaker } from "arrow-resilience-kit";

const breaker = await CircuitBreaker.create({ failureThreshold: 5, resetTimeoutMillis: 30_000 });
const result = await breaker.execute(() => callExternalService());

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

Current state: "Closed", "Open", or "HalfOpen".

Link copied to clipboard
fun <T> execute(block: () -> Promise<T>): Promise<T>

Executes block through the circuit breaker. Rejects with an error if the circuit is open.

Link copied to clipboard
fun <T> executeOrFallback(fallback: () -> Promise<T>, block: () -> Promise<T>): Promise<T>

Executes block, falling back to fallback if the circuit is open.

Link copied to clipboard

Current consecutive-failure count.

Link copied to clipboard
fun onStateChange(listener: (oldState: String, newState: String) -> Unit)

Registers listener to be called (with the old and new state names) on every state change.

Link copied to clipboard

Manually resets the circuit breaker to closed state.

Link copied to clipboard

Current half-open success count.

Link copied to clipboard
fun trip(): Promise<Unit>

Manually opens the circuit breaker.